import {
  ErrorRequestHandler,
  Request,
  Response,
  response,
  NextFunction,
} from "express";
import { tokenTime } from "../../config";
import { findtitlelimit, userinfo, type asyncPromise } from "../../interface";
import ArticleCommentSer from "../../services/ArticleCommentSer";
import { routerHandleReturn } from "../../type";
import { info, err } from "../middleware/infoerr";

export default {
  async add(req: Request, res: Response, next: NextFunction) {
    try {
      if (
        req.body.id &&
        req.body.createdTime &&
        !Object.is(+req.body.id, NaN) &&
        req.body.content
      ) {
        const data = {
          name: req.signedCookies.feifan.name,
          ArticleId: +req.body.id,
          content: req.body.content as string,
          createdTime: req.body.createdTime,
          imgUrl: req.signedCookies.feifan.imgUrl,
        };
        const result = await ArticleCommentSer.add(data);
        return info(res, "ok", result);
      } else return err(res, "id错误", { id: req.body.id });
    } catch (error) {
      next(error);
    }
  },
};
